package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.ParkingBiz;
import guda.stark.dal.dao.ParkingDAO;
import guda.stark.dal.dataobject.ParkingDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class ParkingBizImpl implements ParkingBiz{

    private final static Logger logger = LoggerFactory.getLogger(ParkingBizImpl.class);

    @Autowired
    private ParkingDAO parkingDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            ParkingDO parkingDO = parkingDAO.getParkingById(id);
            bizResult.data.put("parkingDO", parkingDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query Parking error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = parkingDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<ParkingDO> parkingList = parkingDAO.selectForPage(baseQuery);
            bizResult.data.put("parkingList", parkingList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view Parking list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            parkingDAO.delParkingById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete parking error", e);
        }
        return bizResult;
    }

    public BizResult create(ParkingDO parkingDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = parkingDAO.insert(parkingDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create Parking error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(ParkingDO parkingDO) {
        BizResult bizResult = new BizResult();
        try {
            parkingDAO.updateByIdSelective(parkingDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update Parking error", e);
        }
        return bizResult;
    }


}
